package com.mushiengine.core {
import com.mushiengine.collection.HashMap;
import com.mushiengine.test.objects.ExampleBean;
import com.mushiengine.test.objects.InjectedBean;

import com.mushiengine.test.objects.TopBean;

import flexunit.framework.TestCase;

import mx.utils.DescribeTypeCache;

import nl.demonsters.debugger.MonsterDebugger;

public class InjectorTest extends TestCase{

    private var _injector:Injector;

    public function InjectorTest() {
    }


    override public function setUp():void {
        _injector = new Injector();
    }


    override public function tearDown():void {
       _injector = null;
    }

    public function testInstanceIsCreatedWhenClassIsGiven():void {
        assertNotNull(_injector.injectViaClass(ExampleBean));
    }


    public function testMetaDataIsExaminedForInjectedBean():void {
        var classDesc : XMLList = XMLList(DescribeTypeCache.describeType(InjectedBean).typeDescription);
        assertTrue(_injector.injectMetaDataExist(classDesc));
    }

    public function testMetaDataIsExaminedForExpBean():void {
        var classDesc : XMLList = XMLList(DescribeTypeCache.describeType(ExampleBean).typeDescription);
        assertFalse(_injector.injectMetaDataExist(classDesc));
    }

    public function testThatAllIjectionAreMade():void {
        var injectedBean:InjectedBean = _injector.injectViaClass(InjectedBean);
        assertTrue(injectedBean.expBean is ExampleBean);
    }

    public function testShouldReturnCorrectInstanceWhenNoInjectionReq():void {
        var expBean:ExampleBean = _injector.injectViaClass(ExampleBean);

        assertTrue(expBean is ExampleBean);
    }

    public function testShouldAssignCorrectInstanceToInjectedProperty():void {
        var injectedBean:InjectedBean = _injector.injectViaInstance(new InjectedBean());
        assertNotNull(injectedBean.expBean);
    }

    public function testWhenNoMetaDataExistThebeanInstanceIsReturned():void {
        var exampleBean:ExampleBean = new ExampleBean();
        assertNotNull(_injector.injectViaInstance(exampleBean));
    }


    public function testShouldRecurseTo2LevelViaInatnace():void {
        var topBean:TopBean = _injector.injectViaInstance(new TopBean());

        assertTrue(topBean.injectBean is InjectedBean);
        assertTrue(topBean.injectBean.expBean is ExampleBean);

    }

    public function testShouldRecurseTo2LevelViaClass():void {
        var topBean:TopBean = _injector.injectViaClass(TopBean);

       /* assertTrue(topBean.injectBean is InjectedBean);
               assertTrue(topBean.injectBean.expBean is ExampleBean);*/
			assertNotNull(topBean.injectBean);
			
			assertNotNull(topBean.injectBean.expBean);

    }
}
}